{include file="common/head"/}
<style>
.wqs-qrcode {
    padding: 15px;
}

.wqs-qrcode a {
    display: block;
    margin-top: 10px;
    width: 200px;
    height: 40px;
    font-size: 16px;
    /*font-weight: bold;*/
    text-align: center;
    line-height: 40px;
    border: 1px solid #C9C9C9;
    background-color: #fff;
}

.wqs-qrcode a:hover {
    opacity: .8;
    border-color: #009688;
    color: #333;
}
</style>

<div class="layui-fluid"><div class="layui-card">

<div class="layui-card-body">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>系统公告管理</legend>
    </fieldset>

    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload">
            {:lang('search')}
        </button>
        <a href="{:url('')}" class="layui-btn">显示全部</a>
 <!--       <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>-->

       <a href="{:url('add')}?cid={:input('param.cid')}" class="layui-btn" style="float:right;"><i class="fa fa-plus" aria-hidden="true"></i>添加</a>
       <div style="clear: both;"></div>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}


<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10" />
</script>

<script type="text/html" id="open">
    {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-sm" lay-event="open">正常</a> 
    {{# }else{ }}
    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="open">异常</a> 
    {{# } }}
</script>

<script type="text/html" id="action">
    <a href="{:url('edit')}?id={{d.id}}&cid={:input('param.cid')}" class="layui-btn layui-btn-sm">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>
<script>
layui.use('table', function() {
    var table = layui.table, $ = layui.jquery;

    var tableIn = table.render({
        id: 'notice',
        elem: '#list',
        url: '{:url("index")}', 
        method: 'post',
        page: true,
        cols: [
            [
//              { checkbox: true, fixed: true },
                { field: 'id', title: '{:lang("id")}', width: 80,sort: true, fixed: true },
                { field: 'Title', title: '标题', width: 600 },
                { field: 'DateTime', title: '发布时间', width: 200, align: 'center'},
                { width: 160, align: 'center', toolbar: '#action'}
            ]
        ],
        limit: 20
    });
    //搜索
    $('#search').on('click', function() {
        var key = $('#key').val();
        if ($.trim(key) === '') {
            layer.msg('{:lang("pleaseEnter")}关键字！', { icon: 0 });
            return;
        }
        tableIn.reload({
            where: { key: key }
        });
    });
    table.on('tool(list)', function(obj) {
        var data = obj.data;
        if (obj.event === 'open') {
            var loading = layer.load(1, { shade: [0.1, '#fff'] });
            $.post('{:url("statusAttence")}', { 'id': data.id }, function(res) {
                layer.close(loading);
                if (res.status === 1) {
                    if (res.open === 1) {
                        obj.update({
                            open: '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="open">开启</a>'
                        });
                    } else {
                        obj.update({
                            open: '<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="open">禁用</a>'
                        });
                    }
                    tableIn.reload();
                } else {
                    layer.msg('操作失败！', { time: 1000, icon: 2 });
                    return false;
                }
            })
        } else if (obj.event === 'del') {
            layer.confirm('您确定要删除吗？', function(index) {
                var loading = layer.load(1, { shade: [0.1, '#fff'] });
                $.post("{:url('del')}", { id: data.id }, function(res) {
                    layer.close(loading);
                    if (res.code === 1) {
                        layer.msg(res.msg, { time: 1000, icon: 1 });
                        tableIn.reload();
                    } else {
                        layer.msg(res.msg, { time: 1000, icon: 2 });
                    }
                });
                layer.close(index);
            });
        } else if (obj.event === 'qrcode') {
            var loading = layer.load(1, { shade: [0.1, '#fff'] });
            $.post('{:url("createQrcode")}', { 'id': data.id }, function(res) {
                layer.close(loading);
                if (res.code === 1) {
                    layer.msg(res.msg, { time: 1000, icon: 1 });
                    return false;
                } else {
                    layer.msg(res.msg, { time: 1000, icon: 2 });
                    return false;
                }
            })
        } else if (obj.event === 'downqrcode') {
            var html = '<div class="wqs-qrcode">';
            html += "<a class='' href='{:url(\'downQrcode\')}?id="+data.id+"&type=1'>民主测评</a>";
            html += "<a class='' href='{:url(\'downQrcode\')}?id="+data.id+"&type=2'>服务对象</a>";
            html += "</div>";
            console.log('name:' + data.name + " id:" + data.id);
            //边缘弹出
            layer.open({
                type: 1,
                title: '二维码下载',
                content: html,
                id: 'LAY_qrcode',
                btn: '关闭全部',
                btnAlign: 'c' //按钮居中
                    ,
                shade: 0 //不显示遮罩
                    ,
                yes: function() {
                    layer.closeAll();
                }
            });


        }else if (obj.event === 'tongji') {
            var html = '<div class="wqs-qrcode">';
            html += "<a class='' href='{:url(\'Wqs/Excel/leader\')}?id="+data.id+"'>民主测评</a>";
            // html += "<a class='' href='{:url(\'wqs\')}?id="+data.id+"'>服务对象</a>";
            html += "</div>";
            console.log('name:' + data.name + " id:" + data.id);
            //边缘弹出
            layer.open({
                type: 1,
                title: data.name+'统计结果下载',
                content: html,
                id: 'LAY_qrcode',
                btn: '关闭全部',
                btnAlign: 'c' //按钮居中
                    ,
                shade: 0 //不显示遮罩
                    ,
                yes: function() {
                    layer.closeAll();
                }
            });
        }
    });
    $('body').on('blur', '.list_order', function() {
        var id = $(this).attr('data-id');
        var sort = $(this).val();
        var loading = layer.load(1, { shade: [0.1, '#fff'] });
        $.post('{:url("deptOrder")}', { id: id, sort: sort }, function(res) {
            layer.close(loading);
            if (res.code === 1) {
                layer.msg(res.msg, { time: 1000, icon: 1 });
                tableIn.reload();
            } else {
                layer.msg(res.msg, { time: 1000, icon: 2 });
            }
        })
    });
    $('#delAll').click(function() {
        layer.confirm('确认要删除所有选中项吗？', { icon: 3 }, function(index) {
            layer.close(index);
            var checkStatus = table.checkStatus('ad'); //test即为参数id设定的值
            var ids = [];
            $(checkStatus.data).each(function(i, o) {
                ids.push(o.id);
            });
            var loading = layer.load(1, { shade: [0.1, '#fff'] });
            $.post("{:url('delAll')}", { ids: ids }, function(data) {
                layer.close(loading);
                if (data.code === 1) {
                    layer.msg(data.msg, { time: 1000, icon: 1 });
                    tableIn.reload();
                } else {
                    layer.msg(data.msg, { time: 1000, icon: 2 });
                }
            });
        });
    });
})
</script>